import threading,timeit,time,re,math,multiprocessing

def worker(dataArr,st):

    if st == 1:
        print("密集计算开始..")
        #time.sleep(2)
        per = 10000
        row = 48532
        col = 25
        counter = 0
        tNum = math.ceil(row/per) 
        st = timeit.default_timer()
        for row in range(tNum):
            t = threading.Thread(target=subWorker,args=[row*per,per])
            t.start()
        # for i in range(row):
        #     for k in range(col):
        #         pow(100,30)
        et = timeit.default_timer()
        print("密集计算完成..counter=",counter,"t=",et-st)
         
    for item in range(2):
        dataArr.append(st*10+item+1)

    print("worker dataArr =",dataArr,"st=",st)

def subWorker(stIdx,per):
    print("subWorker stIdx=",stIdx)
    col = 25
    for i in range(per):
        for k in range(col):
            pow(100,30)

def protoFind():
    configPbFile = f"protos/config.proto"
    
    temp = """
    message t_UpgradeConfig{
   int32 id = 1;//道具id
   int32 level = 2;//等级
   string costItems = 3;//奖励

}
    message t_ItemConfig{
   int32 id = 1;//道具id
   string name = 2;//名字
   string icon = 3;//图标地址
   int32 cat = 4;//大类
   int32 kind = 5;//小类

}message t_asasConfig

    """
    
    with open(configPbFile,"r",encoding="utf8") as f:
        content = f.read()
        print("content=",content)
        p = re.compile(r"message\s*?t_ItemConfig.*?{.*?}",re.DOTALL)
        mat= re.findall(p,temp)
        print("mat=",mat)
    
    html_str = """
    <html>
        <head><title>Page title</title></head>
        <body>
            <p>Paragraph 1</p>
            <p>Paragraph 2</p>
        </body>
    </html>
    """  
  
    # 匹配所有的 <p> 和 </p> 标签  
    p_tags = re.findall(r'<p.*?>.*?</p>', html_str)  
    
    print(p_tags)  # 输出：['Paragraph 1', 'Paragraph 2']
    text = '这是一个{示例}字符串，其中包含多个大括号内的内容：{example1}、{example2}、{example3}。'  
  
    # 使用正则表达式匹配所有大括号内的内容  
    matches = re.findall(r'\{.*?\}', temp)  
    print("matches=",matches)

def processWorker(idx):
    for item in range(9000000):
        pow(200,30)
    print("processWorker idx=",idx)
        

if __name__=="__main__":
    total = 5
    # dataArr = []
    # ths = []
    # for i in range(total):
    #     tempName = "th_"+str(i)
    #     t = threading.Thread(target=worker,args=[dataArr,i+1],name=tempName)
    #     t.start()
    #     print("activeCount ",threading.activeCount(),"启动了线程=",tempName)
    #     ths.append(t)

    # print("++最后的数据 activeCount=",threading.activeCount(),threading.current_thread().name)
    # print("++当前数据dataArr =",dataArr)
    # # while threading.activeCount()>1:
    # #     continue
    # print("++最终的数据 dataArr =",dataArr)
    # dataArr2 = multiprocessing.Array("i",total)
    # pnum = 5
    # st = timeit.default_timer()
    # pool = multiprocessing.Pool(pnum)
    # queue = multiprocessing.Queue(5)
    # pool.map_async(processWorker,[1,2,3])
    # for i in range(total):
    #     # temp = i
    #     # p = multiprocessing.Process(target=processWorker,args=[dataArr2,temp,])
    #     # p.start()
    #     pool.apply_async(processWorker,args=[queue,i,])
    
    # pool.close()
    # pool.join()
    protoFind()
    
    # print("++最终的数据  pool queue cost=",timeit.default_timer()-st,"pnum=",pnum)
    